Repository navigation
fix: keep the declared test() type when no test case class is bound - #26
Merged
MrPunyapal merged 1 commit intoNov 2, 2026
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change preserving Pest’s declared test() return type when no test case class is bound.
No open issues 🎉
What changed in this PR
Fixes false undefined-method errors by preserving Pest’s declared test() return type when no test case class is bound. Explicit class bindings still narrow the type, and closure $this inference remains unchanged.
Changes:
- Adds class-bound-only resolution while sharing existing class and trait resolution logic.
- Updates bare
test()return typing andtodo()proxy handling to use the new resolver. - Adds regression fixtures covering global traits, hook-only bindings, and explicit class bindings.
| File | Description |
|---|---|
tests/Type/GlobalTraitBindingTest.php |
Runs type assertions for unbound helpers and class-bound files. |
tests/Type/global-trait-binding-extension.neon |
Configures analysis of the new fixtures. |
tests/GlobalTraitBindingTestCase.php |
Provides the fixture-specific type inference configuration. |
tests/Fixtures/GlobalTraitBinding/tests/Pest.php |
Defines global trait, class, and hook-only bindings. |
tests/Fixtures/GlobalTraitBinding/modules/Billing/tests/Helpers.php |
Asserts that helpers retain Pest’s declared return type. |
tests/Fixtures/GlobalTraitBinding/modules/Billing/tests/Feature/billing-test-function.php |
Asserts class-bound typing and trait method resolution. |
src/Type/Pest/TestFunctionReturnTypeExtension.php |
Narrows test() only when a class is bound. |
src/Type/Pest/TestFunctionProxyMethodExtension.php |
Applies the class-binding requirement to todo() proxy handling. |
src/Type/Pest/PestTestCaseType.php |
Adds class-bound-only resolution and extracts shared type construction. |
Review effort: Balanced
MrPunyapal
approved these changes
Nov 2, 2026
MrPunyapal
left a comment
Member
There was a problem hiding this comment.
Thanks for the fix and regression coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since v5.3.0 (#22), a bare
test()is typed as the bound test case. Files that only globalin()-less traits apply to (e.g.pest()->use(WithCachedRoutes::class)) fall back to plainPHPUnit\Framework\TestCase. Helper files that calltest()(e.g.tests/Helpers.phpwithtest()->postJson(...)) then report falsemethod.notFounderrors:Fix
Narrow
test()only when a binding actually names a test case class. With trait-only or hook-only bindings,test()keeps Pest's declaredTestCall|HigherOrderTapProxy, as in 5.2.2.PestTestCaseType::resolveIfClassBound()is new.TestFunctionReturnTypeExtensionandTestFunctionProxyMethodExtensionnow use it.$thisinference in closures is unchanged.BoundTestCasePrivateMemberRuledoesn't need changes, because it only checks$thisinside closures and never sees a baretest().Tests
The new
tests/Fixtures/GlobalTraitBindingfixture has a global trait, a class binding and a hook-only chain:test()keeps the declared type. Without the fix it fails withPHPUnit\Framework\TestCase.test()still resolves toCustomTestCase.